import unittest

def stringparts(string, minlength=3):
	'''return all consequentially string parts of length minlength. "abcd",3 -> "abc", "bcd".'''
	for i in range(0,len(string)):
		s1 = string[i:i+minlength]
		if s1 and len(s1)==minlength: yield s1

def yap(string):
	'''find number of yap.'''
	nyap = 0
	f = filter(lambda x:x[0]=='y' and x[-1]=='p', stringparts(string))
	return len(list(f))

class Test(unittest.TestCase):
	def testYap(self):
		yaps = [("yap",1), ("yypp",2), ("yyyppxyxpyxpyypp",6)]
		for string, n in yaps:
			self.assertEqual(yap(string), n)
	def test_partition(self):
		s = ""
		l = list(stringparts(s))
		self.assertEqual(l, [])
		
		s = "a"
		l = list(stringparts(s))
		self.assertEqual(l, [])

		s = "abcd"
		l = list(stringparts(s))
		self.assertEqual(l, ['abc', 'bcd'])
		
		


unittest.main()
